package www.controller.googleMap;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import www.google.GoogleDTO;
import www.google.GoogleMgr;
import www.view.JSONView;

public class LocationController implements Controller {
	private GoogleMgr googleMgr;
	
	
	public void setGoogleMgr(GoogleMgr googleMgr) {
		this.googleMgr = googleMgr;
	}


	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView();
		
		JSONObject jobj = new JSONObject();
		JSONArray jarray = new JSONArray();
		
		List list = googleMgr.getList();
		
		for(int i =0; i<list.size() ; i++){
			GoogleDTO googleDTO = (GoogleDTO) list.get(i);
			jarray.add(googleDTO.toJSONObject());
		}
		
		jobj.put("data", jarray);
		
		mv.addObject("jobj",jobj);
		
		mv.setView(new JSONView());
		
		return mv;
	}

}
